package com.wen.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wen.mapper.ProductMapper;
import com.wen.pojo.InStore;
import com.wen.pojo.Product;
import com.wen.utils.PageBean;
import com.wen.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.wen.mapper.InStoreMapper;
import com.wen.service.InStoreService;

import java.util.List;

@Service
public class InStoreServiceImpl implements InStoreService{

    @Autowired
    private InStoreMapper inStoreMapper;

    //分页查询全部入库单
    @Override
    public PageBean<InStore> allListStore(Integer pageNum,Integer pageSize,InStore inStore) {
        PageBean<InStore> pb = new PageBean<>();
        PageHelper.startPage(pageNum,pageSize);
        List<InStore> inStores = inStoreMapper.allList(inStore);
        Page<InStore> p = (Page<InStore>) inStores;

        pb.setTotal(p.getTotal());
        pb.setItems(p.getResult());
        return pb;
    }

    //确认入库单
    @Override
    public Result confirmInstore(InStore inStore) {
        int i = inStoreMapper.updIsIn(inStore);

        if(i>0){
            Product p = new Product();
            p.setInNum(inStore.getInNum());
            p.setProductId(inStore.getProductId());


            inStoreMapper.updKc(p);

            return Result.ok(200,"成功",null);
        }else{
            return Result.fail(1,"失败");
        }
    }
}
